package utils;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.CRC32;
import java.util.zip.Checksum;

public class Hashes {
	private static final int NUM_OF_GROUPS = 5;
	private static final Checksum checksumEngine = new CRC32();
	
	public static int getGroupIdFromServerId(int serverID) {
		return serverID % NUM_OF_GROUPS;
	}
	
	
	/*gets from list, put into quarum to get server*/
	
	public static List<Integer> getGroupIdListFromClientId(int clientID){
		List<Integer> groups = new ArrayList<Integer>();
		int firstGroupId = clientID % 5;
		int secondGroupId = firstGroupId - 1;
		while(!(firstGroupId >= NUM_OF_GROUPS && 
				secondGroupId < 0)) {
			if(firstGroupId < NUM_OF_GROUPS) {
				groups.add(firstGroupId ++);
			}
			if(secondGroupId >= 0) {
				groups.add(secondGroupId --);
			}
		}
		return groups;
	}
	
	public static long CheckSum(byte[] bytes)
	{
		// Compute CRC-32 checksum
		checksumEngine.update(bytes, 0, bytes.length);
		long temp = checksumEngine.getValue();
		checksumEngine.reset();

		return temp;

	}
 
}
